#include<iostream>
#include<signal.h>
#include<sys/types.h>
#include<unistd.h>
using namespace std;
//接下来是观看core
int main()
{
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    //来一个除零错误
    int a=10;
    a/=0;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    cout<<"Hello,world"<<endl;
    return 0;
}

















/*void printpending(sigset_t& pending)
{
    cout<<"我是进程["<<getpid()<<"]:";
    for(int i=31;i>0;i--)
    {
        if(sigismember(&pending,i))//如果pending中第i位的信号存在，则打印1
        {
            cout<<"1";
        }
        else
        {
            cout<<"0";
        }
    }
    cout<<endl;
}
sigset_t oldblock;
void handler(int signum)
{
    cout<<"Signal received:"<<signum<<"开始递达该信号"<<endl;
    sigset_t p;
    sigpending(&p);
    printpending(p);
    cout<<"######################################"<<endl;
}
int main()
{
    signal(SIGINT,handler);
    //这次我们将信号二进行屏蔽
    sigset_t block;//block用于屏蔽信号集
    //首先清空这一个信号集
    sigemptyset(&block);
    sigaddset(&block,SIGINT);//此时还没有被设置入block信号集
    //将block信号集加入当前进程的信号屏蔽集
    sigprocmask(SIG_BLOCK,&block,&oldblock);
    int cnt=0;
    while(1)
    {
        sigset_t pending;
        sigpending(&pending);
        printpending(pending);
        sleep(1);
        cnt++;
        if(cnt==20)
        {
            cout<<"我是进程["<<getpid()<<"]，我将信号二解除屏蔽"<<endl;
            //将block信号集从当前进程的信号屏蔽集中移除
            sigprocmask(SIG_SETMASK,&oldblock,NULL);
        }
    }
    return 0;
}*/











/*void handler(int signum)
{
    cout<<"Signal received:"<<signum<<endl;
}
void Alarm(int signum)
{
    cout<<"Alarm signal received:"<<signum<<endl;
    alarm(1);
}
int main()
{
    signal(SIGALRM,Alarm);
    alarm(1);
    while(1)
    {
        pause();
    }
    return 0;
}*/
/*int main()
{
    int cnt=0;
    for(int i=1;i<32;i++)
    {
        signal(i,handler);
    }
    for(int i=1;i<32;i++)
    {
        if(i==9||i==19)//9和19无法被自定义捕捉
        {
            continue;
        }
        kill(getpid(),i);
    }
    return 0;
}*/